package com.hulk.dryad.admin.controller.other;

import com.anji.captcha.model.common.CaptchaTypeEnum;
import com.anji.captcha.model.common.ResponseModel;
import com.anji.captcha.model.vo.CaptchaVO;
import com.anji.captcha.service.CaptchaService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.hulk.dryad.common.component.R;
import com.hulk.dryad.common.util.SpringContextHolder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author hulk
 * @Date 2019/12/15
 */
@ApiSort(2)
@Api(value = "captcha", tags = "滑块验证码")
@RequestMapping("/captcha")
@RestController
public class ValidateCodeController {

    /**
     * 生成验证码
     *
     */
    @ApiOperation(value = "codeGen", notes = "生成滑块验证码")
    @ApiOperationSupport(order = 0)
    @GetMapping("/code/gen")
    public R codeGen()  {
        CaptchaVO vo = new CaptchaVO();
        vo.setCaptchaType(CaptchaTypeEnum.BLOCKPUZZLE.getCodeValue());
        CaptchaService captchaService = SpringContextHolder.getBean(CaptchaService.class);
        ResponseModel responseModel = captchaService.get(vo);
        return R.ok(responseModel);
    }
    @ApiOperation(value = "codeCheck", notes = "验证滑块验证码")
    @ApiOperationSupport(order = 1)
	@GetMapping("/code/check")
    public R codeCheck(@RequestParam(value="pointJson",required = true) String pointJson, @RequestParam(value="token",required = true) String token)  {
        CaptchaVO vo = new CaptchaVO();
        vo.setPointJson(pointJson);
        vo.setToken(token);
        vo.setCaptchaType(CaptchaTypeEnum.BLOCKPUZZLE.getCodeValue());
        CaptchaService captchaService = SpringContextHolder.getBean(CaptchaService.class);
        ResponseModel responseModel = captchaService.check(vo);
        return R.ok(responseModel);
    }


}
